<?php
/**
 * Created by PhpStorm.
 * User: 王新宇
 * Date: 2021/11/18
 * Time: 11:08
 */
namespace app\admin\model;

use think\Model;


class Goods extends Model
{
    //获取器
    public function getAddtimeAttr($v)
    {
        return date("Y-m-d H:i:s",$v);
    }
    //搜索器
    //模糊搜索
    public function searchKeywordsAttr($q,$v)
    {
        $q->where('a.name','like',"%{$v}%");
    }
    //推荐
    public function searchIsShowAttr($q,$v)
    {
        $q->where('is_show','=',$v);
    }
    //热门
    public function searchIsHotAttr($q,$v)
    {
        $q->where('is_hot','=',$v);
    }
    //下架
    public function searchIsDownAttr($q,$v)
    {


        $q->where('is_down','in',$v);

    }
    //分类
    public function searchCidAttr($q,$v)
    {
        $q->where('cid','=',$v);
    }

    public static function getGoodsList($where)
    {
        $list = Goods::alias('a')
            ->withSearch(array_keys($where),$where)
            ->leftJoin('ecm_category b','a.cid=b.id')
            ->field("a.id,a.name,a.photo_x,a.price,b.name as aname,a.addtime,a.is_show,a.is_down,a.is_hot")
            ->paginate([
            'list_rows'=>3,
            'query' => $where
        ]);

        return $list;
    }
}